package com.example.demo.utils;

import com.example.demo.mapper.entity.*;
import com.example.demo.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author Lucy
 * @create 2024-03-17 14:46
 */
//帮助计算学生广告优先级的工具类
public class PriorityUtil {

    @Autowired
    private AdService service;


    public double calculatePriority(int studentId, int gender, int collegeId, int nativePlace) {
        Student student = service.selectStudentById(studentId);
        double genderFactor = 0;
        double nativePlaceFactor = 0;
        double collegeFactor = 0;
        if(gender != 0){
            if(gender == 1){
                genderFactor = 1 / service.selectStudentCountByGender(0);
            }else{
                genderFactor = 1 / service.selectStudentCountByGender(1);
            }
        }
        if(nativePlace != 0){
            nativePlaceFactor = 1 / service.selectStudentCountByNativePlace(nativePlace);
        }
        if(collegeId != 0){
            collegeFactor = 1 / service.selectStudentCountByCollege(collegeId);
        }
        AdSetting setting = service.selectSetting();
        double genderWeight = setting.getGenderWeight() * genderFactor;
        double collegeWeight = setting.getCollegeWeight() * collegeFactor;
        double nativePlaceWeight = setting.getNativePlaceWeight() * nativePlaceFactor;
        double priority = genderWeight + collegeWeight + nativePlaceWeight;
        return priority;
    }
}
